#pragma once
#include "process.h"
#include <queue>
#include "pch.h"

typedef struct ST_THREADTASK_OBJ {
	_beginthreadex_proc_type proc;
	void* param;
	HANDLE hEvent;
	bool bHEventRelease;
}THREADTASK;
using std::queue;
class CThreadPool
{
	friend unsigned __stdcall _ThreadProcPoolHandle(void* arg);
private:
	const int m_nThread;
	queue<THREADTASK*> m_queTask;
	queue<HANDLE> m_queThread;
	HANDLE m_hNotifyEvent;
	bool m_bTerminated;
	CRITICAL_SECTION m_csLock;
private:
	void InitThreadPool(int nThread);
	THREADTASK* TakeTask();
	bool addTask(THREADTASK* task);
public:
	CThreadPool(int nThread);
	~CThreadPool();
	bool Execute(_beginthreadex_proc_type threadProc, void* param, HANDLE hEvent,bool bHEventRelease);
	void Shutdown();
	void AwaitTermination();
};
typedef struct ST_THREADPOOLPARAM_OBJ {
	CThreadPool* pool;
}THREADPOOLPARAM,*PTHREADPOOLPARAM;
